#include <iostream>
using namespace std;
struct Apple
{
  int basket;
  string id;
  unsigned short  weight;
  int diameter; 
  Apple()
  {
      
  }
  void show()
  {
      cout<<basket<<" "<<id <<" "<< weight <<" "<< diameter<<endl;
  }
};
int main()
{
    int n;
    cin>>n;
    Apple * apples = new Apple[n];
    for(int i = 0; i<n; i++)
    {
        cin>>apples[i].basket>>apples[i].id;
        cin>>(*(apples+i)).weight >> (*(apples+i)).diameter;
    }   
   // for(int i = 0; i <n; i++)
   //     apples[i].show();
    for(int basket = 1; basket<=999999; basket++)
    {   int cur = 0;
        int maxw = 0;
        for(int i = 0; i<n; i++)
        {
            if(apples[i].basket == basket)
            {
                if(apples[i].weight > maxw)
                {
                    cur = i;
                    maxw = apples[i].weight;
                }
            }
        }
        if(maxw>0)
            apples[cur].show();
        
    }
    
  
}